package com.psm.mobileInterceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.psm.model.IdGenerater;
import com.psm.model.SysUser;

/**
 * Created by cheam on 15/6/19.
 */
public class IndexInterceptor implements Interceptor {
    protected static IdGenerater idGenerater=new IdGenerater();


    public void intercept(Invocation ai) {
        System.out.println("Before invoking " + ai.getActionKey());
        Controller ctl = ai.getController();


        String path = ctl.getRequest().getContextPath();
        String basePath = ctl.getRequest().getScheme() + "://" + ctl.getRequest().getServerName() + ":" + ctl.getRequest().getServerPort() + path + "/";

        ctl.setAttr("root",basePath);

        String login_user_id=ctl.getCookie("login_student_id");

        if(null == login_user_id){
            ctl.redirect("/mobile/login.html");
            return;
        }

        ai.invoke();
        System.out.println("After invoking " + ai.getActionKey());
    }

}
